/*
package com.taotao.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.List;

*/
/**
 * @author wangjin
 * @title: GatewayToken
 * @projectName sw-gateway
 * @description: 过滤器 过滤token
 * @date 2021/12/8 15:48
 *//*

@Component
public class GatewayToken  implements GlobalFilter {
    @Value("${server.port}")
    private String serverPort;

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        // 获取到ServerHttpRequest
        ServerHttpRequest request = exchange.getRequest();
        ServerHttpResponse response = exchange.getResponse();
        List<String> token = request.getHeaders().get("token");
        if (token == null || token.size() == 0) {
            String msg = "token not is null ";
            DataBuffer buffer = response.bufferFactory().wrap(msg.getBytes());
            return response.writeWith(Mono.just(buffer));
        }
        // 网关转发到 会员服务时 会在请求头中传递的 网关端口号
        request = exchange.getRequest().mutate().header("gateway.port", serverPort).build();
        // 传递了token
        // 放行请求
        return chain.filter(exchange.mutate().request(request).build());
    }
}
*/
